package cn.dengta.webapp.user.entity;

import java.util.Date;

import cn.dengta.webapp.base.entity.TimeBasedEntity;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

/**
 * 用户登录统计表
 *
 * @author zw
 * @since 2022-10-09
 */
@Setter
@Getter
@Accessors(chain = true)
@TableName("dt_user_login_statistics")
public class UserLoginStatistics extends TimeBasedEntity {

	private static final long serialVersionUID = 1L;

	/** 总登录天数 */
	Integer totalLoginCount;
	/** 最近登录时间 */
	Date lastLoginTime;
	/** 连续登录天数 */
	Integer continuousLoginCount;
	/** 性别：1=男；0=女 */
	Integer gender;
	/** 总的登录次数（APP启动时会主动上报一次） */
	Integer loginTimes;

	public static UserLoginStatistics of(User sessionUser, Date now) {
		final UserLoginStatistics uls = new UserLoginStatistics();
		uls.setId(sessionUser.getId());
		uls.setTotalLoginCount(1);
		uls.setLastLoginTime(now);
		uls.setContinuousLoginCount(1);
		uls.setGender(sessionUser.getGender().getValue());
		uls.initTime(now);
		return uls;
	}

	public static final String GENDER = "gender";
	public static final String TOTAL_LOGIN_COUNT = "total_login_count";
	public static final String LAST_LOGIN_TIME = "last_login_time";
	public static final String CONTINUOUS_LOGIN_COUNT = "continuous_login_count";

}
